/*
 * setup-PCB.c
 *
 *  Created on: Sep 21, 2013
 *      Author: Joseph DeLong
 *	Edited: Alex Bouvy 9-29-13
 */

#include <stdlib.h>
#include "mpx_pcb.h"
#include "allocPCB.h"
#include "freePCB.h"

/*
 * SetupPCB()
 * Written by Jospeh DeLong, Alex Bouvy
 * Procedures: Setup-PCB 19/32
 * CS 450 LAB Module R2 Feb. 1, 2013
 * Initializes the information in your PCB structure. Does not
 * insert into a queue. Calls Allocate-PCB(), sets state to
 * ready, not suspended (this will change later)
 * Parameters: Process Name, class, priority
 * Returns:
 * 	Pointer to the PCB if successful
 * 	NULL if error, including if one of the parameters is invalid
 */

struct MPX_PCB* setupPCB(char processName[9], int processClass, int priority) {
	//initialize PCB structure:
	struct MPX_PCB* pcb;
	pcb = allocPCB();
/*	printf("pcb address: %d\n",&pcb);
	strcpy((*pcb).processName,procName);
	strcat((*pcb).processName,"\0");*/
	//(*pcb).processName =  processName;
	strcpy((*pcb).processName, processName);
	(*pcb).processID = 0;	
	(*pcb).processClass = processClass;
	(*pcb).priority = priority;
	(*pcb).pcb_state = 1;
	(*pcb).isSuspended = 0;
	(*pcb).next = NULL;
	(*pcb).prev = NULL;
	//(*(*pcb).stack_base) = sys_alloc_mem(STACK_SIZE);
	//(*pcb).stack_top = (*pcb).stack_base + STACK_SIZE;
	(*pcb).memorySize = STACK_SIZE;
	(*pcb).load_address = 0; //this should be memory address
	(*pcb).exec_address = 0; //this should be memory address + line of executable code(?)
/*	printf((*pcb).processName);
	printf("\n");
	printf("PID: %d\n",(*pcb).processID);
	printf("Class: %d\n",(*pcb).processClass);
	printf("Prio: %d\n",(*pcb).priority);
	printf("State: %d\n",(*pcb).pcb_state);
	printf("Suspended?: %d\n",(*pcb).isSuspended);
	printf("Mem Size: %d\n",(*pcb).memorySize);
	printf("Load Address: %d\n",(*pcb).load_address);
	printf("Exec Address: %d\n",(*pcb).exec_address);*/
//	freePCB(pcb);
	return pcb;
}
